package com.isoft.demo01.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.isoft.demo01.dao.OrderDao;
import com.isoft.demo01.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
@Component
public class OrderRepository {
    @Autowired
    OrderDao orderDao;

    public int insert(Order order) {
        return orderDao.insert(order);
    }

    public int updateById(Order order) {
        return orderDao.updateById(order);
    }
    public int deleteById(Integer id) {
        return orderDao.deleteById(id);
    }

    public int deleteByIds(List<Integer> ids) {
        return orderDao.deleteBatchIds(ids);
    }


    public Order getDetailById(Integer id) {
        return orderDao.getDetailById(id);
    }

    public int updateDel( Integer id, Integer isdel){
        return orderDao.updateDel(id,isdel);
    }

    public Page<Order> page(Integer currentPage , Integer size , Integer orderid , Integer allprice , String date ) {
        Page<Order> page = new Page<>() ;
        page.setCurrent(currentPage) ;
        page.setSize(size) ;
        QueryWrapper<Order> wrapper = new QueryWrapper<>() ;
        if(null != orderid) {
            wrapper.eq("orderid" , orderid) ;
        }
        if(null != allprice) {
            wrapper.like("allprice" , allprice) ;
        }
        if(null != date) {
            wrapper.eq("DATE_FORMAT(ordertime,\"%Y-%m-%d\")" , date) ;
        }
        wrapper.orderByDesc("ordertime") ;
        return orderDao.selectPage(page , wrapper) ;
    }


}
